package com.maochang.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maochang.pojo.PsLineInfo;
import com.maochang.pojo.PsPoleInfo;
import com.maochang.pojo.util.Result;
import com.maochang.pojo.util.Result1;
import com.maochang.service.PsLineInfoService;
import com.maochang.service.PsPoleInfoService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/***
 * 杆台管理
 * */

@Slf4j
@RestController
@RequestMapping("/GanTaiGuanLi")
public class GanTaiGuanLi {

    @Resource
    private PsPoleInfoService psPoleInfoService;
    @Resource
    private PsLineInfoService psLineInfoService;

    @GetMapping("/GanTai")
    public ModelAndView index(Model model){
        return new ModelAndView("gantai/GanTaiGuanLi");
    }


    @GetMapping("/GanTaiCha")
    public Result1 ChaXianLu(Integer lineId,Integer isStart, @RequestParam("page") int current, @RequestParam("limit") int size){
        Page<PsPoleInfo> aa= psPoleInfoService.ChaPsPI(lineId,isStart,current,size);
        Result1 list=Result1.success1(aa);
        return list;
    }

    @PostMapping("/add")
    @SneakyThrows
    public Result add(PsPoleInfo psPI){
        psPI.setCreationTime(LocalDateTime.now());
        psPI.setLastUpdateTime(LocalDateTime.now());
        psPI.setLineId(1);
        psPI.setLineCode("XW0001");
        psPI.setCreatedBy("光头强");
        psPoleInfoService.addPsPI(psPI);
        return Result.success("添加用户成功");
    }

    @PostMapping("/del")
    public  Result ShanCHu(Integer id){
        Result result =new Result();
        boolean fAlg=psPoleInfoService.ShanChu(id);
        if(fAlg){
            result.setMsg("成功");
            return result;
        }else {
            result.setMsg("失败");
            return result;
        }
    }

    @PostMapping("/PsPIUpdate")
    public  Result qxTypeUpdate(PsPoleInfo psPoleInfo){
        Result result =new Result();
        boolean fAlg=psPoleInfoService.PIUpdate(psPoleInfo);
        System.out.println(fAlg);
        if(fAlg==true){
            result.setMsg("修改成功");
        }
        return result;
    }

    @PostMapping("/qxZhuAngTaiGai")
    public  Result qxZhuAngTaiGai(Integer id,Integer zhuAngTai){
        Result result =new Result();
        boolean fAlg=psPoleInfoService.QxZhuAngTai(id,zhuAngTai);
        if(fAlg==true){
            result.setMsg("状态更新成功");
        }
        return result;
    }
    /**
     * 查询线路类型
     * @return
     */
    @GetMapping("/XiaLaKuang")
    public List<PsLineInfo> ChaXia(){
        return psPoleInfoService.ChaXia();
    }

    /**
     * 查询线路上的杆台
     */
    @GetMapping("/ChaXianGanTai")
    public  List<PsPoleInfo> chaGanTai(String id){
        List<PsPoleInfo> xianZiShangDeTaiZhi= psLineInfoService.ChaXiaTiao(id);
        return   xianZiShangDeTaiZhi;
    }

}
